<template>
  <div class="coupontype">
          <swiper :options="swiperOption" class="swiper-box swiper-box-c4">
              <swiper-slide class="swiper-item">
                 <volume :data="Conponable" :info='info1' :Clickok='true'></volume>
              </swiper-slide>
              <swiper-slide class="swiper-item">
                 <volume :data="ConponUnable" :info='info2'></volume>
              </swiper-slide>
             <div class="swiper-pagination-cart3" :class="posL" slot="pagination"  ></div>
        </swiper>

        <div v-show="coupontypeZw && wz" class="coupontype-zw" @click="centeruseFn">
          <div>立即使用</div>
        </div>
  </div>
</template>
<script>
  import { mapActions, mapGetters} from 'vuex'
  import {swiper, swiperSlide} from 'vue-awesome-swiper'
  import { Cart2storecoupon } from '@/service/getData'
  import Volume from './centervolume'
  var TAB_NAME = ['可使用', '不可用'];
  var Info = '暂无可使用的优惠券~';
  export default {
    data(){
      return{
          posL: '',
          Conponable:[],
          ConponUnable:[],
          info1:'',
          info2:'',
          info3:'',
          expired: true,
          coupontypeZw: true,
          wz:true,

          swiperOption: {
              pagination: '.swiper-pagination-cart3',
              paginationClickable: true,
              paginationBulletRender(swiper, index, className) {
                return  `<span class="${className} swiper-pagination-bullet-custom">${TAB_NAME[index]}</span>`;
              },

              onTransitionStart: swiper => {
                this.posL = 'active-'+swiper.realIndex;
                if(swiper.realIndex == 1) {
                  this.coupontypeZw = false

                }
                if(swiper.realIndex == 0) {
                  this.coupontypeZw = true
                }
              }
            }
      }
    },
    created(){
      this.init()
      this.$nextTick(() => {
        $('.app-adver')[0] &&  $('.coupontype').addClass('cart2-coupon')

        // $('.coupontype').height($('.coupontype-zw').offset().top - $('.coupontype').offset().top)
        $('.swiper-box-c4 .swiper-wrapper .swiper-item').eq(0).height(
           $('.coupontype-zw').offset().top-$('.swiper-box-c4 .swiper-wrapper').offset().top
        )
        $('.swiper-box-c4 .swiper-wrapper .swiper-item').eq(1).height(
           $('.coupontype-zw').offset().top-$('.swiper-box-c4 .swiper-wrapper').offset().top+$('.coupontype-zw').height()
        )
      })
    },
    computed: {
      ...mapGetters({
        position: 'position'
      }),
      centerAllinfo(){
        return this.$store.state.cart2.centervolumeinfo
      }
    },
    methods:{
        ...mapActions([
          'centeruseFn'
        ]),
        init(){
           var couponList = JSON.parse(sessionStorage.cl);
           var last = couponList.pop();
           if(toString.call(last) == "[object String]") {
              this.$store.dispatch('Centercart2No', last)
           }

           var ablearr = [],
               unablearr = [],
               ableNum = 0,
               unableNum =0;
           for(let i = 0; i < couponList.length; i ++) {
              if(couponList[i].usefulFlag == '1') {
                ablearr.push(couponList[i])
                ableNum++
              }else {
                unablearr.push(couponList[i])
                unableNum++
              }
           }
           if(this.centerAllinfo.length > 0 && ablearr.length > 0) {
              for(let i = 0; i < this.centerAllinfo.length; i++) {
                for(var j=0 ; j < ablearr.length; j++) {
                    if(ablearr[j].couponNum == this.centerAllinfo[i].couponNo) {
                      ablearr[j].cheack = 'cheacked'
                    }
                }
              }
           }

           if(ablearr.length == 0) {
              this.wz = false
           }

           this.Conponable = ablearr;
           this.ConponUnable = unablearr;

            if (ableNum > 0) {
              TAB_NAME[0] = '可使用('+ableNum+')'
            }
            if(unableNum > 0) {
              TAB_NAME[1] = '不可用('+unableNum+')'
            }

            setTimeout(() => {
               var s = $('.swiper-pagination-cart2 span');
                  if(ableNum > 0) {
                    s.eq(0).html('可使用('+ableNum+')');
                  }
                  if(unableNum > 0) {
                    s.eq(1).html( '不可用('+unableNum+')');
                  }
             }, 500)
        },




    },
    components: {
      swiper,
      swiperSlide,
      Volume
    }
  }
</script>
<style lang="scss">

  @function _($px) {
        $rem: $px/50;
        @return #{$rem}rem;
   }
  .coupontype {
    overflow: hidden;
  }
  .swiper-box-c4 {
    height: 100% !important
  }
  .swiper-box-c4  .swiper-wrapper .swiper-item {
    overflow: hidden;
    overflow-y: auto
  }
  .coupontype-zw {
    background-color: #fff;
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100%;
    height: _(100);
    z-index: 11;

      & > div {
        width: _(702);
        margin: _(10) auto 0;
        height: _(80);
        line-height: _(80);
        background-color: #ff782d;
        border-radius: _(4);
        text-align: center;
        color: #fff;
        font-size: _(30);
      }

  }
  .swiper-box-c4 .swiper-wrapper {
     top: _(80);
  }
  .swiper-pagination-cart3 {
    position: absolute;
    top: 0;
    width: 100%;
    height: _(80);
  }
  .swiper-pagination-cart3 span{
    width: 50%;
    height: _(80);
    line-height: _(80);
    font-size: _(26);
    display:inline-block;
    margin:0 !important;
    background-color:#fff;
    border-radius: 0;
    opacity: 1 ;
    text-align: center;
    color:#444;
    letter-spacing: _(-0.16);
  }
  .swiper-pagination-cart3 span.swiper-pagination-bullet-active {
    color:#ff782d;
  }

  .swiper-pagination-cart3:after {
    position: absolute;
    content: '';
    left: 15%;
    bottom: 0;
    width: _(143);
    height: _(4);
    background-color: #ff782d;
    transition: left 0.1s;
  }
  .swiper-pagination-cart3.active-1:after {
    left: 65%
  }
  .swiper-pagination-bullet{
    position: relative;
  }
  .bg-cl{
    color:#fff;
    background: #ff782d;
    padding: _(1) _(10);
    position: absolute;
    border-radius:_(20);
    line-height: _(30);
    top:.1rem

  }

</style>
<style lang="scss" scoped>
    @function _($px) {
        $rem: $px/50;
        @return #{$rem}rem;
   }

   .conpontype-tab {
      ul {
        background-color: #fff;
        overflow: hidden;

          li {
              float: left;
              width: 33.33%;
              text-align: center;
          }
      }
   }

  .bg-cl{
    border: 1px solid #000;
  }


</style>
